let isName=false;
$(".ipt1").change(function(){
    console.log(111);
    let naReg = /^\w{3,18}$/;
    let username=$(".ipt1").val();
   if(naReg.test(username)){
    $(".ipt1").next().html("格式正确");
    $(".ipt1").next().css("color", "green");
     isName=true;
   }else{
    $(".ipt1").next().html("格式错误");
    $(".ipt1").next().css("color", "red");
    isName=false;
   }
   zhuangtai()
})
    let isPw=false;
$(".ipt2").change(function(){
    let pwRge = /^.{3,32}/;
    let password=$(".ipt2").val();
   if(pwRge.test(password)){
    $(".ipt2").next().html("格式正确");
    $(".ipt2").next().css("color", "green");
    isPw=true;
   }else{
    $(".ipt2").next().html("格式错误");
    $(".ipt2").next().css("color", "red");
    isPw=false;
   }
   zhuangtai()
})

$("button").click(function(){
   if(isName && isPw){
       let username=$(".ipt1").val();
       let password=$(".ipt2").val();
       let  url='http://jx.xuzhixiang.top/ap/api/login.php'
       $.get(url,{username,password},function(v){
           console.log(v);
           alert(v.msg);
          
           if(v.code==1){
            location.href='../index.html'
            localStorage.setItem("id", v.data.id);
           }
       })
   }
})

/* 检查两个输入框的状态 */
function zhuangtai(){
    if(isName && isPw){
        $("button").prop("disabled",false)
    }else{
        $("button").prop("disabled",true)
    }
}